package com.BeeFramework.Utils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * User: howie Date: 13-5-11 Time: 下午4:09
 */
public class TimeUtil {

	//振越  年月日
	public static String timeSimpleFormat(String timeStr) {
		Date date = null;
		try {
			SimpleDateFormat format = new SimpleDateFormat(
					"yyyy年MM月dd日");
			date = format.parse(timeStr);
			Date date2 = format.parse(timeStr);
			timeStr=format.format(date2);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return timeStr;

	}
	//振越 年月日时分秒
	public static String timeFormat(String timeStr) {
		Date date = null;
		try {
			SimpleDateFormat format = new SimpleDateFormat(
					"yyyy/MM/dd HH:mm:ss");
			date = format.parse(timeStr);
			Date date2 = format.parse(timeStr);
			timeStr=format.format(date2);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return timeStr;
		
	}

	public static String timeAgo(String timeStr) {
		Date date = null;
		try {
			SimpleDateFormat format = new SimpleDateFormat(
					"yyyy/MM/dd HH:mm:ss zzz");
			date = format.parse(timeStr);

		} catch (ParseException e) {
			e.printStackTrace();
			return "";
		}

		long timeStamp = date.getTime();

		Date currentTime = new Date();
		long currentTimeStamp = currentTime.getTime();
		long seconds = (currentTimeStamp - timeStamp) / 1000;

		long minutes = Math.abs(seconds / 60);
		long hours = Math.abs(minutes / 60);
		long days = Math.abs(hours / 24);

		if (seconds < 60) {
			return "刚刚";
		} else if (seconds < 120) {
			return "1分钟前";
		} else if (minutes < 60) {
			return minutes + "分钟前";
		} else if (minutes < 120) {
			return "1小时前";
		} else if (hours < 24) {
			return hours + "小时前";
		} else if (hours < 24 * 2) {
			return "1天前";
		} else if (days < 30) {
			return days + "天前";
		} else if (days < 365) {
			return new BigDecimal(days / 30).setScale(0,
					BigDecimal.ROUND_HALF_UP) + "个月前";
		} else {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
			String dateString = formatter.format(date);
			return dateString;
		}

	}

}
